package com.plan.commen.serviceImpl;

import com.plan.commen.bean.User;
import com.plan.commen.bean.layuiBean.VoPage;
import com.plan.commen.mapper.UserMapper;
import com.plan.commen.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.plan.commen.bean.layuiBean.ResultPage;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 冯政尚
 * @since 2020-11-30
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

   /** 分页查询User
     * @param user  前端传进的参数
     * @return 返回统一分页信息
     */
    @Override
    public  ResultPage findUserByPage(VoPage voPage, User user){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", (voPage.getPage() - 1) * voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        paramMap.put("user", user);
        List<User> list = baseMapper.selectMyPage(paramMap);
        Integer count = baseMapper.countMyPage(paramMap);
        ResultPage<User> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }
}
